home *** CD-ROM | disk | FTP | other *** search
- Path: ucl.ac.uk!nobody
- From: ucecb09@ucl.ac.uk (Robert Byrne)
- Newsgroups: comp.lang.c++
- Subject: Re: mixing static and const qualifiers for class members
- Date: Wed, 20 Mar 1996 14:37:49 GMT
- Organization: University College London
- Message-ID: <1996Mar20.143749.90333@ucl.ac.uk>
- NNTP-Posting-Host: crs4gw.crs4.it
- Originator: daemon@crs4gw.crs4.it
-
- Paulo Eduardo Neves <neves@lmf-di.puc-rio.br> writes:
-
- >James Youngman wrote:
- >>
- >> class Foo
- >> {
- >> static const int nPositions = 6;
- >> int nData[nPositions];
- >> }
- >>
- >> ...how is this done?
-
- >class Foo {
- > static const int nPositions;
- >};
-
- >const int Foo::nPositions = 6;
-
- >You also won't be able to declare the array this way, since nPosition
-
- >class Foo {
- > Foo():nData(new int[nPositions]){}
- > static const int nPositions;
- > int *nData;
- >};
-
- The simple way to declare integral class constants is with an enumeration.
-
- class Foo{
- enum constants{nPositions = 6};
- public:
- int nData[nPositions];
- };
-
-
- Rob
-
- --
- Robert Byrne `I think therefore I am' says rather more than
- ucecb09@ucl.ac.uk is strictly certain.' -Bertrand Russell
-
-